package com.ic.base;

/**
 * Description: 分页类
 * Author: zen_hu
 * Date  : 2017/2/14
 * Time  : 10:25
 */
public class PageInfo {
	// 当前页
	private int currentPage;
	// 总页数
	private int totalPage;
	// 总记录数
	private int totalSize;
	// 开始位置
	private int startIndex;
	// 结束位置
	private int endIndex;
	// 每页的记录数
	private int PAGE_SIZE;

	public int getCurrentPage() {
		return currentPage > totalPage ? totalPage : currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage == 0 ? 1 : currentPage;
	}

	public int getPAGE_SIZE() {
		return PAGE_SIZE;
	}

	public void setPAGE_SIZE(int PAGE_SIZE) {
		this.PAGE_SIZE = PAGE_SIZE;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public int getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
		if (PAGE_SIZE == 0) {
			PAGE_SIZE = 2;
		}
		totalPage = totalSize / PAGE_SIZE;
		totalPage += (totalSize % PAGE_SIZE != 0) ? 1 : 0;

		startIndex = (getCurrentPage() - 1) * PAGE_SIZE;

		if (startIndex < 0) {
			startIndex = 0;
		}
		endIndex = startIndex + PAGE_SIZE;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public PageInfo() {
		this(1);
	}

	public PageInfo(int currentPage) {
		this.currentPage = currentPage == 0 ? 1 : currentPage;
	}
}
